package com.dpmc.service;
 
import java.util.HashMap;
import java.util.Map;

import javax.ejb.Stateless;

import com.common.util.ObjectUtils;
import com.core.service.AppBaseService;
import com.dpmc.entity.*;

/**
 * 银行管理
 */
@Stateless
public class SVC_YHGL extends AppBaseService implements SVC_YHGLRemote,
		SVC_YHGLLocal {

	@Override
	public Map ADD_SKYH(Map param) {
		TB_YHGL_SKYH bo = ObjectUtils.mapToJavaBean(param, TB_YHGL_SKYH.class);
		bo.setID(bo.uuid());
		bo.setCREATE_TIME(getOpTime(param));
		bo.setOP_ITEM(getOpTime(param));
		bo.setOPID(getOpid(param));
		getJpaDao().save(bo);
		
		Map yhzh=(Map)param.get("OBJECT_TB_YHZH");
		if(yhzh!=null){
			TB_YHZH yhzh_vo =  ObjectUtils.mapToJavaBean(yhzh, TB_YHZH.class);
			yhzh_vo.setID(yhzh_vo.uuid());
			yhzh_vo.setGLLX("TB_YHGL_SKYH");
			yhzh_vo.setGLID(bo.getID());
			yhzh_vo.setCREATE_TIME(getOpTime(param));
			yhzh_vo.setOP_ITEM(getOpTime(param));
			yhzh_vo.setOPID(getOpid(param) );  
			getJpaDao().save(yhzh_vo);
		} 
		
		//商户财务账户
	    Map cwzh = new HashMap();
		cwzh.put("ZHLX", "TB_YHGL_SKYH");
		cwzh.put("GLID", bo.getID()); 
		copySysParam(param,cwzh);
		getServiceInterface().doService("SVC_CWGL", "ADD_ZH", cwzh);
		
		return ObjectUtils.javaBeanToMap(bo);
	}

	@Override
	public Map UPD_SKYH(Map param) {
		TB_YHGL_SKYH bo = ObjectUtils.mapToJavaBean(param, TB_YHGL_SKYH.class);
		bo.setOP_ITEM(getOpTime(param));
		bo.setOPID(getOpid(param));
		TB_YHGL_SKYH po = getJpaDao().find(TB_YHGL_SKYH.class, bo.getID());
		ObjectUtils.copyJavaBeanToBean(bo, po, "CREATE_TIME");
		getJpaDao().update(po);
		
		Map yhzh=(Map)param.get("OBJECT_TB_YHZH");
		if(yhzh!=null){
			TB_YHZH yhzh_vo =  ObjectUtils.mapToJavaBean(yhzh, TB_YHZH.class);
			yhzh_vo.setOP_ITEM(getOpTime(param));
			yhzh_vo.setOPID(getOpid(param) ); 
			if(yhzh_vo.getID()==null){
				yhzh_vo.setID(yhzh_vo.uuid());
				yhzh_vo.setGLLX("TB_YHGL_SKYH");
				yhzh_vo.setGLID(bo.getID());
				yhzh_vo.setCREATE_TIME(getOpTime(param)); 
				getJpaDao().save(yhzh_vo);
			} else{
				TB_YHZH yhzh_po =getJpaDao().find(TB_YHZH.class, yhzh_vo.getID());  
				ObjectUtils.copyJavaBeanToBean(yhzh_vo, yhzh_po, "ID","CREATE_TIME","GLLX","GLID"); 
				getJpaDao().update(yhzh_po);
			}
		} 

		return ObjectUtils.javaBeanToMap(po);
	}

	@Override
	public void DEL_SKYH(Map param) {
		TB_YHGL_SKYH dto = ObjectUtils.mapToJavaBean(param, TB_YHGL_SKYH.class);
		TB_YHGL_SKYH po = getJpaDao().find(TB_YHGL_SKYH.class, dto.getID());

		po.setOP_ITEM(getOpTime(param));
		po.setOPID(getOpid(param));
		po.setSTATUS(TB_YHGL_SKYH.STATUS_DEAD);
		getJpaDao().update(po);
	}

}
